
// 订单完成后，进行添加餐品，以及将人物的头像添加的桌子的上面
function finishOrder(seatNumber,id){
    //获取菜单的名称，得到餐品的各种的信息
    const list = document.getElementsByName("menu");
    //将顾客的id号添加到table位置上
    table[seatNumber].userID = id;
    for(let i in list){
        if(list[i].checked === true){
            //假如这个菜品是为true的状态则说明其是被标记的，添加到桌子上的餐单上
            table[seatNumber].list.push(i)

        }
    }
    let tableList = table[seatNumber].list;
    //得到该餐桌的位置，来确定该餐品添加的位置是在哪里
    let parentId = judgeTable(seatNumber);
    let parentElment = $(parentId);
    let secondDiv = document.createElement("div");
    secondDiv.classList = parentId+"-foodList";
    secondDiv.id= parentId+"-foodList";
    parentElment.innerHTML="<div class='table"+id+"'>\n" +
    "  <img src=\"./img/customer"+id +".png\">\n"+
    "</div>"
    parentElment.appendChild(secondDiv);
    //渲染菜单
    let foodList = $(parentId + "-foodList");
    for(let j in tableList){
        let food = document.createElement("div");
        food.className = "food";
        food.innerHTML = dishes[tableList[j]].name;
        foodList.append(food);
    }
    //更改用户的状态为eating,同时将table的状态标记为false不可以选用的状态
    customer[id].status= "eating";
    table[seatNumber].canUse = false;
}
//单品收银,返回该商品的价格
function countFoodPrice(foodName){
    for(let i in dishes){
        if(dishes[i].name === foodName){
            return dishes[i].price;
        }
    }
}
//计算每一个菜的成本
function countFoodOrign(foodName){
    for(let i in dishes){
        if(dishes[i].name === foodName){
            return dishes[i].originPrice;
        }
    }
}
//判断是否是要进行收钱这个状态
function getMoney (seatNumber){
    if((table[seatNumber].dealCount) === (table[seatNumber].list.length)){
        let text = "";
        let customerID = table[seatNumber].userID;
        let customerName = customer[customerID].name;
        let income = table[seatNumber].money;
        customer[customerID].status = "impossible";
        if(income > 0){
            text = customerName + "完成用餐，收获$"+income;
            let totalIncome = $("all_momey");
            let totalIncomeInt = parseInt(totalIncome.innerHTML);
            totalIncomeInt +=parseInt(income);
            totalIncome.innerHTML =""+ totalIncomeInt;
            let alerDiv = $("center_alert_p");
            alerDiv.setAttribute("style","text-align:center;");
            ElMessage("remind",text,3500);
        }else{
            text =customerName +"失望而归，被再让客人挨饿了";
            ElMessage("warning",text,3500);
        }
        //同时清理桌子
        cleanTable(seatNumber);
    }
}

